package com.xaicode.learn.netty.http;

import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.http.HttpServerCodec;

/**
 * @author Locker xaicode@sina.com
 * @version 1.0
 * @date 2021/6/15 0015 23:53
 */
public class NettyHttpServerInitializer extends ChannelInitializer<SocketChannel> {

    @Override
    protected void initChannel(SocketChannel ch) {

        // set handler to pipeline
        ChannelPipeline pipeline = ch.pipeline();

        // add http codec
        /*
            Creates a new instance with the
            default decoder options (maxInitialLineLength (4096}, maxHeaderSize (8192), and maxChunkSize (8192)).
         */
        pipeline.addLast("SelfNettyHttpServerCodec", new HttpServerCodec());

        // add self handler
        pipeline.addLast("SelfNettyHttpServerHandler", new NettyHttpServerHandler());

    }
}
